package com.bdqn.crm.controller;

import com.bdqn.crm.entity.User;
import com.bdqn.crm.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @version 2024-09-06
 * @Author:T369曹任柱
 */
@RestController
public class UserController {
    @Resource
    private UserService userService;

//    @RequestMapping(value = "/getUser",method = RequestMethod.GET)
//    public User getUser(Long usrId){
//        User user=userService.getUser(usrId);
//        return user;
//    }

    @GetMapping(value = "/users")
    public List<User> findAllUsers(){
        List<User> list=userService.findAllUsers();
        return list;
    }

    @GetMapping(value = "/user/{id}")
    public User getUser(@PathVariable("id") Long usrId){
        User user=userService.getUser(usrId);
        return user;
    }

    @PostMapping(value = "/user")
    public void addUser(User user){
        userService.addUser(user);
    }

    @PostMapping(value = "/user")
    public void updateUser(User user){
        userService.updateUser(user);
    }
    @PostMapping(value = "/user/{id}")
    public void deleteUser(@PathVariable("id") Long usrId){
        userService.deleteUser(usrId);
    }
}
